package com.kun.portal.webframe.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by Administrator on 2018/7/5.
 */
@Entity
@Table(
        name = "fbo_maintenance_record"
)
@NamedEntityGraph(name = "MaintenanceRecordPoLazy",
        attributeNodes = {@NamedAttributeNode("equipmentPo"),
                @NamedAttributeNode("maintenancePlan"),
                @NamedAttributeNode("dutyPerson"),
                @NamedAttributeNode("maintenanceUser"),
                @NamedAttributeNode("flightInfoPo")
        })
@DynamicUpdate
public class MaintenanceRecordPo {
    @Id
    @GeneratedValue(
            generator = "id"
    )
    @GenericGenerator(
            name = "id",
            strategy = "uuid"
    )
    @Column(
            name = "id",
            length = 32,
            nullable = false
    )
    private String id;

    @Column(
            name = "maintenance_plan_date"
    )
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd",timezone="Asia/Shanghai")
    @Temporal(TemporalType.DATE)
    private Date maintenancePlanDate;

    @Column(
            name = "maintenance_date"
    )
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @JsonFormat(pattern="yyyy-MM-dd",timezone="Asia/Shanghai")
    @Temporal(TemporalType.DATE)
    private Date maintenanceDate;

    @Column(
            name = "maintenance_content",
            length = 100
    )
    private String maintenanceContent;

    @Column(
            name = "result",
            length = 100
    )
    private String result;




    @OneToOne(targetEntity = MaintenancePlanPo.class,cascade = CascadeType.DETACH)
    @JoinColumn(name = "maintenance_plan_id",referencedColumnName ="id" )
    @JsonIdentityInfo(generator=ObjectIdGenerators.UUIDGenerator.class,property="@id")
    private MaintenancePlanPo maintenancePlan;

    @OneToOne(targetEntity = FwUserPo.class,cascade = CascadeType.DETACH)
    @JoinColumn(name = "repair_person_id",referencedColumnName ="user_ID" )

    private FwUserPo maintenanceUser;
    @OneToOne(targetEntity = FwUserPo.class,cascade = CascadeType.DETACH)
    @JoinColumn(name = "duty_person_id",referencedColumnName ="user_ID" )
    private FwUserPo dutyPerson;

    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
    @JoinColumn(name = "equipment_id", referencedColumnName = "id",insertable = true,updatable = true)
    private EquipmentPo  equipmentPo;

    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
    @JoinColumn(name = "flight_info_id", referencedColumnName = "flight_info_id",insertable = true,updatable = true)
    private FlightInfoPo flightInfoPo;

    @Column(
            name = "flight"
    )
    private Boolean flight;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getMaintenancePlanDate() {
        return maintenancePlanDate;
    }

    public void setMaintenancePlanDate(Date maintenancePlanDate) {
        this.maintenancePlanDate = maintenancePlanDate;
    }

    public Date getMaintenanceDate() {
        return maintenanceDate;
    }

    public void setMaintenanceDate(Date maintenanceDate) {
        this.maintenanceDate = maintenanceDate;
    }

    public String getMaintenanceContent() {
        return maintenanceContent;
    }

    public void setMaintenanceContent(String maintenanceContent) {
        this.maintenanceContent = maintenanceContent;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public MaintenancePlanPo getMaintenancePlan() {
        return maintenancePlan;
    }

    public void setMaintenancePlan(MaintenancePlanPo maintenancePlan) {
        this.maintenancePlan = maintenancePlan;
    }

    public FwUserPo getMaintenanceUser() {
        return maintenanceUser;
    }

    public void setMaintenanceUser(FwUserPo maintenanceUser) {
        this.maintenanceUser = maintenanceUser;
    }

    public FwUserPo getDutyPerson() {
        return dutyPerson;
    }

    public void setDutyPerson(FwUserPo dutyPerson) {
        this.dutyPerson = dutyPerson;
    }

    public EquipmentPo getEquipmentPo() {
        return equipmentPo;
    }

    public void setEquipmentPo(EquipmentPo equipmentPo) {
        this.equipmentPo = equipmentPo;
    }

    public FlightInfoPo getFlightInfoPo() {
        return flightInfoPo;
    }

    public void setFlightInfoPo(FlightInfoPo flightInfoPo) {
        this.flightInfoPo = flightInfoPo;
    }

    public Boolean getFlight() {
        return flight;
    }

    public void setFlight(Boolean flight) {
        this.flight = flight;
    }
}
